package org.infinitest.intellij.idea;

import java.io.File;

import com.intellij.openapi.compiler.CompileContext;
import com.intellij.openapi.compiler.CompileStatusNotification;
import com.intellij.openapi.compiler.CompilerManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ProjectRootManager;
import org.infinitest.intellij.ProjectCompiler;

public class IdeaProjectCompiler implements ProjectCompiler
{
  private Project project;

  public IdeaProjectCompiler(Project project)
  {
    this.project = project;
  }

  public void forceRebuild()
  {
    CompilerManager.getInstance(project).rebuild(new DoNothingNotification());
  }

  public File getSdkHomePath()
  {
    Sdk sdk = ProjectRootManager.getInstance(project).getProjectJdk();
    if (sdk == null)
    {
      return null;
    }
    return new File(sdk.getHomePath());
  }

  private static class DoNothingNotification implements CompileStatusNotification
  {
    public void finished(boolean aborted, int errors, int warnings, CompileContext compileContext)
    {
    }
  }
}
